<template>
  <div>
    <el-form :model="form"
             v-loading="loading"
             label-width="120px"
             style="width: 30%;">
      <el-form-item label="收费金额">
        <el-input v-model="form.value"></el-input>
      </el-form-item>
      <el-form-item label="收费提示信息">
        <el-input type="textarea"
                  autosize
                  v-model="form.desc"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
                   @click="preservation">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { setTimeout } from "timers";
export default {
  data() {
    return {
      loading: true,
      form: {
        value: "",
        desc: ""
      }
    };
  },
  created() {
    this.axios({
      method: "get",
      url: "/system/show"
    })
      .then(res => {
        if (res.data.code === 0) {
          this.form.value = res.data.result[0].value / 100;
          this.form.desc = res.data.result[1].value;
        } else {
          this.message(res.data.msg, "error");
        }
      })
      .catch(error => {
        this.message(error, "error");
      });
  },
  mounted() {
    setTimeout(() => {
      this.loading = false;
    }, 500);
  },
  methods: {
    preservation() {
      let data = new URLSearchParams();
      data.append("payMoney", parseInt(this.form.value * 100));
      data.append("payInfo", this.form.desc);
      this.axios({
        method: "post",
        url: "/system/setSetting",
        data
      })
        .then(res => {
          if (res.data.code === 0) {
            this.message(res.data.msg, "success");
          } else {
            this.message(res.data.msg, "error");
          }
        })
        .catch(error => {
          this.message(error, "error");
        });
    }
  }
};
</script>

<style scoped>
</style>